<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no">
		<title>签到</title>
		<script src="/js/jquery/jquery.min.js"></script>
		<link rel="stylesheet" href="/js/attendance/css/public.css"/>
		<link rel="stylesheet" href="/js/attendance/css/signin.css"/>
		<script src="/js/attendance/js/myAttendance.js"></script>

		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/editTravels.css"/>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/form/jquery.form.js"></script>
		<script src="/js/My97DatePicker/WdatePicker.js"></script>
		<script src="/js/common.js"></script>
		<script src="/js/checkLogin.js"></script>
		<script src="../js/plugins/eleditor/webuploader.min.js"></script>
		<script src="../js/plugins/eleditor/Eleditor.min.js"></script>
		<script src="../js/My97DatePicker/WdatePicker.js"></script>
	</head>

	<body>
		<div class="search-head">
			<div class="row nav-search" >
				<div class="col-5">
					<a href="profiles.html">
						<span><i class="fa fa-chevron-left fa-2x"></i></span>
					</a>
				</div>
				<span><h>我的签到</h></span>
			</div>
		</div>
		<div class="top flex flex-align-end flex-pack-center flex-warp" >
			<div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
				<div class="out-2 flex flex-align-center flex-pack-center">
					<div class="signBtn">
						<strong id="sign-txt">签到</strong>
						<span>本月已签<em id="sign-count"></em>天</span>
					</div>
				</div>
			</div>
		</div>
		<div class="tips" id="tips">今日还未签到,签到可以获得10积分参与抽奖哦</div>
		<div class="Calendar">
			<div id="toyear" class="flex flex-pack-center">
				<div id="idCalendarPre">&lt;</div>
				<div class="year-month">
					<span id="idCalendarYear">2018</span>年<span id="idCalendarMonth">6</span>月
				</div>
				<div id="idCalendarNext">&gt;</div>
			</div>
			<table border="1px" cellpadding="0" cellspacing="0">
				<thead>
					<tr class="tou">
						<td>日</td>
						<td>一</td>
						<td>二</td>
						<td>三</td>
						<td>四</td>
						<td>五</td>
						<td>六</td>
					</tr>
				</thead>
				<tbody id="idCalendar">
				</tbody>
			</table>
		</div>
		<script language="JavaScript">
            var num;
            var signtime;
            var prevMouthTimess;
			$(function () {
				$.get(baseUrl+"users/"+ user.id+"/attendances", function (data) {
                    signtime= data.lastSignTime;
                    num=data.signNum;
                   /* var arry=data.signTimes.split(";");
                    arry.push(3);
                    arry.push(5);*/
                   cale.SignIn(data.signTimess);
					prevMouthTimess=data.prevMouthTimess;
					if (data) {
						var date = new Date();
						var arr = [];
						arr = (data.signTime+'-').split("-");
						if ((arr[0] == date.getFullYear()) & (arr[1] == date.getMonth() + 1) &
								(arr[2] == date.getDate())) {
							$("#tips").html("今天已签到,已获得10积分");
							isSign = true;
							cale.SignIn()
						}
						$("#sign-count").html(data.signTimess.length);
					}
				});
			})
            var isSign = false;
			var myday = new Array(); //已签到的数组
    	/*	myday[0] = "1528646400"
		    myday[1] = "1528387200"
			myday[2] = "1525708800"
*/
			var cale = new Calendar("idCalendar", {
				qdDay: myday,
				onToday: function(o) {
					o.className = "onToday";
				},
				onSignIn: function (){
					$$("sign-txt").innerHTML = '已签到';
				},
				onFinish: function() {
					$$("sign-count").innerHTML = myday.length //已签到次数
					$$("idCalendarYear").innerHTML = this.Year;
					$$("idCalendarMonth").innerHTML = this.Month; //表头年份

				}
			});
			$$("idCalendarPre").onclick = function() {
				cale.PreMonth(prevMouthTimess);
			}
			$$("idCalendarNext").onclick = function() {
				cale.NextMonth();
			}
			//添加今天签到
			$$("signIn").onclick = function() {
				if(isSign == false) {
					var res = cale.SignIn(null);
					if(res == '1') {
						$$("sign-txt").innerHTML = '已签到';
						$$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
						isSign = true;
						$.post(baseUrl+"users/"+ user.id+"/attendances",{date:new Date()}, function (data) {
                           if(data==7){
                               $(document).dialog({
                                   type: 'notice',
                                   infoText: '恭喜您连续签到7天,赠送额外50积分!',
                                   autoClose: 2*1000
                               });
                           }
                        });
					} else if (res == '2'){
						$$("sign-txt").innerHTML = '已签到';
						alert('今天已经签到了')
					}
				} else {
					alert('今天已经签到了')
				}
			}
		</script>

	</body>

</html>